export function down(url) {
	const downloadTask = uni.downloadFile({
		url,
		success: (res) => {
			console.log(res)
			if (res.statusCode === 200) {
				uni.showToast({
					icon: 'none',
					title: '文件路径' + res.tempFilePath,
					position: 'top'
				})

				uni.showModal({
					confirmText: '打开',
					content: '文件下载成功，是否打开',
					confirmColor: '#13B0FA',
					success: function(res2) {
						if (res2.confirm == true) {
							console.log(res2, '？？')
							uni.openDocument({
								filePath: res.tempFilePath,
								success: function(res3) {
									console.log('打开文档成功', res3);
								}
							});
						}
					}
				})
			}
			// this.dd = res.tempFilePath;
			console.log(res.tempFilePath);
		}
	});

	downloadTask.onProgressUpdate((res) => {
		console.log('下载进度' + res.progress);
		console.log('已经下载的数据长度' + res.totalBytesWritten);
		console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite);
	});
}

function randomSort() {
	return Math.random() < 0.5 ? -1 : 1
}
export function color16() { //十六进制颜色随机
	var hex = Math.floor(Math.random() * 16777216).toString(16); //生成ffffff以内16进制数
	while (hex.length < 6) { //while循环判断hex位数，少于6位前面加0凑够6位
		hex = '0' + hex;
	}
	return '#' + hex; //返回‘#'开头16进制颜色
}
export function GetPercent(num, total) {
	/// <summary>
	/// 求百分比
	/// </summary>
	/// <param name="num">当前数</param>
	/// <param name="total">总数</param>
	num = parseFloat(num);
	total = parseFloat(total);
	if (isNaN(num) || isNaN(total)) {
		return "-";
	}
	return total <= 0 ? "0" : (Math.round(num / total * 10000) / 100.00);
}
// /进行经纬度转换为距离的计算
function Rad(d) {
	return d * Math.PI / 180.0; //经纬度转换成三角函数中度分表形式。
}
export function getMapDistance(lat1, lng1, lat2, lng2) {
	var radLat1 = Rad(lat1);
	var radLat2 = Rad(lat2);
	var a = radLat1 - radLat2;
	var b = Rad(lng1) - Rad(lng2);
	var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
		Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
	s = s * 6378.137; // EARTH_RADIUS;
	s = Math.round(s * 10000) / 10000; //输出为公里
	//s=s.toFixed(2);
	return s;


}
